package org.openkanban.server.dao;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openkanban.server.dao.ActivityDao;
import org.openkanban.server.dao.BoardDao;
import org.openkanban.server.dao.UserDao;
import org.openkanban.server.domain.Activity;
import org.openkanban.server.domain.Board;
import org.openkanban.server.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "test-applicationContext.xml" })
@TransactionConfiguration(transactionManager = "transactionManager")
@Transactional
public class BoardDaoCascadeTest2 {

    @Autowired
    BoardDao boardDao;

    @Autowired
    ActivityDao activityDao;

    @Autowired
    UserDao userDao;

    Board board;

    User user;

    @Before
    public void setUp() {
	user = new User();
	user = userDao.createUser(user);

	board = new Board();
	board.setBoardName("halloboard");

	board = boardDao.createBoard(board, user.getUserId());

	Activity activity = new Activity();
	activity.setActivityName("meinactivity");
	Activity activity2 = new Activity();
	activity2.setActivityName("meinactivity nummer 2");

	activity = boardDao.addActivityToBoard(board.getBoardId(), activity);
	activity2 = boardDao.addActivityToBoard(board.getBoardId(), activity2);

	assertEquals(2, board.getActivities().size());

    }

    @Test
    public void test() {
	List<Activity> aList = activityDao.getAll();

	assertTrue(aList.size() > 0);
    }
}
